package com.wave.lib;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author Wave.Zhang
 * @version 1.0
 * @data 15/6/1
 */
public class SwipeItemView extends ViewGroup{

    View mLeftView;

    View mRightView;

    View mFrontView;

    public SwipeItemView(Context context) {
        super(context);
    }

    public SwipeItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (changed) {
            //int w = this.getDisplay().getWidth();
            mLeftView = getChildAt(0);// 获取滑动菜单的view
            mFrontView = getChildAt(1);// 获得主页view
            mRightView = getChildAt(2);// 获得主页view

            // 相当于fill_parent
            //mFrontView.measure(getWidth(),getHeight());
            mFrontView.layout(0, 0, getWidth(), mFrontView.getMeasuredHeight());

            mLeftView.measure(mLeftView.getMeasuredWidth(),mLeftView.getMeasuredHeight());
            mLeftView.layout(-(mLeftView.getMeasuredWidth()), 0, 0, mLeftView.getMeasuredHeight());

            mRightView.measure(mRightView.getMeasuredWidth(),mRightView.getMeasuredHeight());
            mRightView.layout( getWidth(), 0, getWidth() + mRightView.getMeasuredWidth(), mRightView.getMeasuredHeight());
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        final int count = getChildCount();
        /*for (int i = 0; i < count; i++) {
            getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
        }*/
        if(count > 1){
           getChildAt(1).measure(widthMeasureSpec, heightMeasureSpec);
        }
    }
}
